<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thêm Hãng</title>

<link href="../style/cssqt.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
	function kiemtrathemhang()
	{
		var s=document.formthem;
		var sdt = document.formthem.dienthoai.value;
		if(s.mahang.value=='')
		{
			document.getElementById("mahang_error").style.display = "block";
			document.getElementById("mahang_error").innerHTML="Bạn chưa nhập mã hãng laptop!";
			s.mahang.focus();
			return false;	
		}
		else
			document.getElementById("mahang_error").style.display = "none";
			
		if(s.tenhang.value=='')
		{
			document.getElementById("tenhang_error").style.display = "block";
			document.getElementById("tenhang_error").innerHTML="Bạn chưa nhập tên hãng laptop!";
			s.tenhang.focus();
			return false;	
		}
		else
			document.getElementById("tenhang_error").style.display = "none";
		
		
		
		if(s.diachi.value=='')
		{
			document.getElementById("diachi_error").style.display = "block";
			document.getElementById("diachi_error").innerHTML="Bạn chưa nhập địa chỉ!";
			s.diachi.focus();
			return false;	
		}
		else
			document.getElementById("diachi_error").style.display = "none";
		
		if(s.dienthoai.value=='')
		{
			document.getElementById("dienthoai_error").style.display= "block";
			document.getElementById("dienthoai_error").innerHTML=" Bạn chưa nhập điện thoại!";
			s.dienthoai.focus();
			return false;	
		}
		else
			document.getElementById("dienthoai_error").style.display = "none";
			
		if(sdt.length<10)
		{
			document.getElementById("dienthoai_error").style.display= "block";
			document.getElementById("dienthoai_error").innerHTML=" Số điện thoại không hợp lệ!";
			s.dienthoai.focus();
			return false;	
		}
		else
			document.getElementById("dienthoai_error").style.display = "none";
		
			
			
					if(isNaN(s.dienthoai.value))
		{
			document.getElementById("dienthoai_error").style.display= "block";
			document.getElementById("dienthoai_error").innerHTML="Điện thoại phải là số!";
			s.dienthoai.focus();
			return false;	
		}
		else
			document.getElementById("dienthoai_error").style.display = "none";
			
			
			if(s.email.value=='')
		{
			document.getElementById("email_error").style.display = "block";
			document.getElementById("email_error").innerHTML=" Bạn chưa nhập email!";
			s.email.focus();
			return false;	
		}
		else
		{
			var email = document.getElementById('email');
	 		 var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(email.value)) {
				document.getElementById("email_error").style.display = "block";
			    document.getElementById("email_error").innerHTML=" Bạn nhập email chưa đúng!";
			    s.email.focus();
				return false;
			 }
			else
			{
				document.getElementById("email_error").style.display = "none";	
			}
		}
		
			
			
		
			return true;
}
</script>
<script>
{
	function nhapsonguyen(e)
	{
		var keyword = null;
		if(window.event)
		{
			keyword = window.event.keyCode;	
		}
		else
		{
			keyword = e.which;	
		}
		
		if(keyword<48 || keyword>57)
		{
			if(keyword==48 || keyword==127)
			{
				return;	
			}
			return false;
		}
		
	}
	
}
</script>
</head>

<body>
<?php
include("../config/config.php");
$mahang = $_POST["mahang"];
$tenhang = $_POST["tenhang"];
$diachi = $_POST["diachi"];
$dienthoai = $_POST["dienthoai"];
$email = $_POST["email"];

if(isset($_POST["them"]))
{

	$lenhthem = "insert into hanglaptop values('$mahang','$tenhang','$diachi','$dienthoai','$email')";
	$kqthem = mysql_query($lenhthem);
	if($kqthem)
	{
		?>
		<script>
		alert('thêm thành công!');
		location.href='indexqt.php?act=hang';
		</script>
	   <?php
	  
		
	}
}

?>
<form id="formthem" name="formthem" method="post" action="" onsubmit="return kiemtrathemhang()">
  <table width="1110" border="1" align="center" cellpadding="0" cellspacing="0" class="table_khachhang">
    <tr>
      <td height="30" colspan="2" align="center" class="title_table">Thêm Hãng Laptop</td>
    </tr>
    <tr>
      <td width="304" height="30">Mã hãng</td>
      <td width="490" height="30"><label for="mahang"></label>
      <input name="mahang" type="text" class="onhapdangkyvuaqt" id="mahang" value="<?php  echo $_POST["mahang"];   ?>" placeholder="Mã hãng laptop" /><font color="#FF0000">(*)
      <span class="hide error" id="mahang_error"> </span> </font></td>
    </tr>
    <tr>
      <td height="30">Tên hãng</td>
      <td height="30"><label for="tenhang"></label>
      <input name="tenhang" type="text" class="onhapdangkyvuaqt" id="tenhang" value="<?php  echo $_POST["tenhang"];   ?>" placeholder="Tên hãng laptop"/><font color="#FF0000">(*)
      <span class="hide error" id="tenhang_error"> </span> </font></td>
    </tr>
    <tr>
      <td height="30">Địa chỉ</td>
      <td height="30"><label for="diachi"></label>
      <input name="diachi" type="text" class="onhapdangkyvuaqt" id="diachi" value="<?php  echo $_POST["diachi"];   ?>" placeholder="Địa chỉ"/><font color="#FF0000">(*)
      <span class="hide error" id="diachi_error"> </span> </font></td>
    </tr>
    <tr>
      <td height="30">Điện thoại</td>
      <td height="30"><label for="dienthoai"></label>
      <input name="dienthoai" type="text" class="onhapdangkyvuaqt" id="dienthoai" placeholder="Điện thoại" onkeypress="return nhapsonguyen(event); " value="<?php  echo $_POST["dienthoai"];   ?>" maxlength="12" /><font color="#FF0000">(*)
      <span class="hide error" id="dienthoai_error"> </span> </font></td>
    </tr>
    <tr>
      <td height="30">Email</td>
      <td height="30"><label for="email"></label>
      <input name="email" type="text" class="onhapdangkyvuaqt" id="email" value="<?php  echo $_POST["email"];   ?>" placeholder="Email" /><font color="#FF0000">(*)
      <span class="hide error" id="email_error"> </span> </font></td>
    </tr>
    <tr>
      <td height="30" colspan="2" align="center"><input name="them" type="submit" class="nutbutton" id="them" value="Thêm" /></td>
    </tr>
  </table>
</form>
</body>
</html>